package com.bitcat.base.ext

import androidx.appcompat.app.AppCompatActivity
import com.bitcat.base.widget.dialog.LoadingDialog
import kotlinx.coroutines.CoroutineScope


var customLoadingDialog: LoadingDialog? = null

//显示加载框
fun AppCompatActivity.showLoadingExt(message: String = "加载中...",coroutineScope: CoroutineScope? = null){
    //关闭
    dismissLoadingExt()
    //判断当前activity是否结束
    if (!isFinishing){
        if (customLoadingDialog == null){
            customLoadingDialog = LoadingDialog.Builder(this)
                .setTitle(message)
                .setCancelable(true)
                .setCancelOutside(true)
                .setCoroutineScope(coroutineScope)
                .build()
        }
        customLoadingDialog?.show()
    }
}


//关闭加载框
fun AppCompatActivity.dismissLoadingExt(){
    if (!isFinishing){
        customLoadingDialog?.dismiss()
    }
}